import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import {VxeFormItemProps, VxeGridPropTypes} from "@/components/VxeTable";
import util from "@/utils/util";


//表格列名
export const columns: BasicColumn[] = [
  {
    title: '用户名',
    dataIndex: 'userName',
    width: 130,

  },
  {
    title: '试卷名称',
    dataIndex: 'paperName',
  },
  {
    title: '得分',
    dataIndex: 'score',
    width: 130,
  },
  {
    title: '创建时间',
    width: 160,
    dataIndex: 'createTime',
  },
  {
    title: '交卷时间',
    width: 160,
    dataIndex: 'endTime',
  },

];


/**
 */
export const vxeTableColumns: VxeGridPropTypes.Columns = [

  {
    title: '序号',
    type: 'seq',
    fixed: 'left',
    width: '40',
    align: 'center',
  },
  {
    title: '订单标识号',
    field: 'biaoShiHao',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
    width: 92,
  },

  {
    title: '物料名称',
    field: 'bmname',
    align: 'center',
    // filters: [{ data: '' }],
    // filterRender: {
    //   name: 'VxeInput',
    // },
    width: 150,
  },
  {
    title: '型号',
    field: 'mmodel',
    align: 'center',
    width: 82,
  },
  {
    title: '数据来源',
    field: 'source',
    align: 'center',
    width: 56,
  },
  {
    title: '业务员',
    field: 'yeWuYuan',
    align: 'center',
    width: 56,
  },
  {
    title: '交期',
    field: 'jiaoHuoDate',
    align: 'center',
    sortable:true,
    width: 75,
  },
  {
    title: '销售数量',
    field: 'xiaoShouShuLiang',
    align: 'center',
    width: 65,
  },
  {
    title: '齐套数量',
    field: 'qiTaoNum',
    slots:{
      default:"qiTaoNum_slot",
    },
    align: 'center',
    width: 58,
  },
  {//车、钻、磨、电镀
    title: '车',
    field: 'cheNum',
    slots:{
      default:"cheNum_slot"
    },
    align: 'center',
    width: 56,
  },
  {
    title: '钻',
    field: 'zhuanNum',
    slots:{
      default:"zhuanNum_slot"
    },
    align: 'center',
    width: 55,
  },
  {
    title: '磨',
    field: 'moNum',
    slots:{
      default:"moNum_slot"
    },
    align: 'center',
    width: 55,
  },
  {
    title: '电镀',
    field: 'dianDuNum',
    slots:{
      default:"dianDuNum_slot"
    },
    align: 'center',
    width: 55,
  },
  {
    title: '包装数量',
    field: 'baoZhuanNum',
    align: 'center',
    slots:{
      default:"baoZhuanNum_slot"
    },
    width: 58,
  },

  {
    title: '未完成数量',
    field: 'totalUnDo',
    slots:{
      default:"totalUnDo_slot"
    },
    align: 'center',
    width: 70,
  },
  {
    title: '是否完成',
    field: 'isQiTao',
    align: 'center',
    slots:{
      default:"isQiTao_slot",
    },
    width: 58,
  },
  {
    title: '是否齐套',
    field: 'izQiTao',
    align: 'center',
    filters: [
      { label: '齐套', value: 1 },
      { label: '缺料', value: 0 },
    ],

    slots:{
      default:"isQueLiao_slot",
    },
    width: 75,
  },
  // {
  //   title: '包装资料是否上传',
  //   field: 'izWenjianUp',
  //   slots:{
  //     default:"izWenjianUp_slot",
  //   },
  //   align: 'center',
  //   width: 75,
  // },

  {
    title: '缺料情况',
    field: 'queLiaos',
    align: 'center',
    slots:{
      default:"queLiaos_slot",
    },
    width: 200,

  },
  {
    title: '备注',
    field: 'note',
    width: 130,
    align: 'center',
    slots:{
      default:"note_slot",
    },
  },
  {
    title: '下单时间',
    field: 'bdate',
    sortable:true,

    width: 130,
    align: 'center',
  },


  {
    width: 130,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

/**
 * 往前推6个月 并取那个月的1号
 */
function getSixMonthsAgoFirstDay() {
  // 获取当前日期
  const today = new Date();

  // 计算6个月前的年份和月份
  let year = today.getFullYear();
  let month = today.getMonth() - 6; // 月份从0开始计数

  // 处理月份小于0的情况（跨年份）
  if (month < 0) {
    year += Math.floor(month / 12);
    month = (month % 12 + 12) % 12;
  }

  // 创建6个月前1号的日期对象
  const sixMonthsAgo = new Date(year, month, 1);

  // 格式化日期为 yyyy-mm-dd 格式
  const formattedYear = sixMonthsAgo.getFullYear();
  const formattedMonth = String(sixMonthsAgo.getMonth() + 1).padStart(2, '0');
  const formattedDay = String(sixMonthsAgo.getDate()).padStart(2, '0');

  return `${formattedYear}-${formattedMonth}-${formattedDay}`;
}


export const searchFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'paperName',
    label: '试卷名称',
    component: 'Input',
    colProps: { span: 8 },
  },

];


export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'keyword',
    title: '搜索',
    itemRender: {
      props: {
        placeholder: '请输入',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    field: 'isQiTao',
    title: '是否完成',
    visible:true,
    itemRender: {
      name: 'VxeSelect',
      props: {
        clearable:true
      },
      options:[
        {label:"完成",value:0},{label:"未完成",value:1}]

      },
  },
  {
    span: 5,
    field: 'startTime',
    title: '订单起始日期',
    // itemRender: {}, slots: { default: 'dateArrItem' },
    itemRender: {
      name: 'VxeDatePicker',
      defaultValue:getSixMonthsAgoFirstDay(),
      props: {
        clearable: true,
      }
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];





export const formSchema: FormSchema[] = [

  {
    field: 'deptName',
    label: '部门',
    component:"Input",
    required: true,
  },
  {
    field: 'roleName',
    label: '岗位',
    component:"Input",
    required: true,
  },
  {
    field: 'education',
    label: '学历要求',
    component:"Input",
    required: false,
  },
  {
    field: 'workNum',
    label: '工作经验',
    component:"InputNumber",
    required: false,
  },
  {
    field: 'manageNum',
    label: '管理经验',
    component:"InputNumber",
    required: false,
  },

  {
    field: 'industryNum',
    label: '行业经验',
    component:"InputNumber",
    required: false,
  },
  {
    field: 'specialtyNum',
    label: '专业经验',
    component:"InputNumber",
    required: false,
  },
  {
    field: 'specialty',
    label: '学历专业',
    component:"Input",
    helpMessage:"请填写专业名称",
    required: false,
  },

];



export const itemColumns: VxeGridPropTypes.Columns = [
  {
    title: '来料检编号',
    field: 'zhuTid',
    showOverflow: 'title',
    align: 'center',
    width: 120,
  },
  {
    title: '标识号',
    field: 'biaoShiHao',
    showOverflow: 'title',
    align: 'center',
    width: 120,
  },
  // {
  //   title: '物料名称',
  //   field: 'mname',
  //   showOverflow: 'title',
  //   align: 'center',
  //   width: 80,
  // },
  {
    title: '物料类型(导入)',
    field: 'mtname',
    showOverflow: 'title',
    align: 'center',
    width: 150,
  },
  {
    title: 'bom物料编号',
    field: 'bommtid',
    showOverflow: 'title',
    align: 'center',
    width: 150,
  },

  {
    title: '来料允收数量',
    field: 'quantity',
    showOverflow: 'title',
    align: 'center',
    width: 120,
  },
  {
    title: '销售数量',
    field: 'xiaoShouShuLiang',
    showOverflow: 'title',
    align: 'center',
    width: 120,
  },
  {
    title: '缺料数量',
    field: 'unDo',
    showOverflow: 'title',
    align: 'center',
    slots:{
      default:"unDo_slot",
    },
    width: 120,
  }
  ]


export const itemColumns2: VxeGridPropTypes.Columns = [
  {
    title: '物料编号前缀',
    field: 'no',
    showOverflow: 'title',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
  },
  {
    title: '名称',
    field: 'name',
    showOverflow: 'title',
    align: 'center',
  },

  {
    title: '一级物料编号',
    field: 'pno',
    showOverflow: 'title',
    align: 'center',
  },

]

/**
 * bom 清单
 */
export const itemColumns3: VxeGridPropTypes.Columns = [
  {
    title: '物料编号',
    field: 'mtid',
    showOverflow: 'title',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
  },
  {
    title: '物料名称',
    field: 'mname',
    showOverflow: 'title',
    align: 'center',
    filters: [{ data: '' }],
    filterRender: {
      name: 'VxeInput',
    },
  },

  {
    title: '规格',
    field: 'guige',
    showOverflow: 'title',
    align: 'center',
  },
  {
    title: '型号',
    field: 'mmodel',
    showOverflow: 'title',
    align: 'center',
  },
  {
    title: '类型编号',
    field: 'mttid',
    showOverflow: 'title',
    align: 'center',
  },
  {
    title: '类型名称',
    field: 'mtname',
    showOverflow: 'title',
    align: 'center',
  },
]
